package tools;

import beans.CartBean;
import beans.CartItemBean;
import beans.ProductBean;

public class Utility {
	public static int ConvertCategory(String category) {
		if (category.equals("All")) {
			return 0;
		} else if (category.equals("Pizza")) {
			return 1;
		} else if (category.equals("Hamberger")) {
			return 2;
		} else if (category.equals("Hotdog")) {
			return 3;
		} else if (category.equals("Sandwich")) {
			return 4;
		} else {
			return 0;
		}
	}
	
	public static String ConvertCategoryInt(int category){
		if (category == 0) {
			return "All";
		} else if (category == 1) {
			return "Pizza";
		} else if (category == 2) {
			return "Hamberger";
		} else if (category == 3) {
			return "Hotdog";
		} else if (category == 4) {
			return "Sandwich";
		} else {
			return "All";
		}
	}
	
	public static String convertCategoryInt_to_imagePath(int category){
		if (category == 0) {
			return "";
		} else if (category == 1) {
			return "images/pizza/";
		} else if (category == 2) {
			return "images/hamberger/";
		} else if (category == 3) {
			return "images/hotdog/";
		} else if (category == 4) {
			return "images/sandwich/";
		} else {
			return "";
		}
	}
	
	public static String ConvertProductList_to_ProductString(CartBean cart){
		StringBuffer productString = new StringBuffer();
		for(int i = 0; i < cart.getItems().size(); i++){
			String productID = String.valueOf(cart.getItems().get(i).getProduct().getID());
			String number = String.valueOf(cart.getItems().get(i).getNumber());
			productString.append(productID + "-" + number + "/");
		}
		
		return productString.toString();
	}
	
	public static CartBean ConvertProductString_to_ProductList(String productString){
		CartBean cart = new CartBean();
		String[] cartItems = productString.split("/");
		for(int i = 0; i < cartItems.length; i++){
			CartItemBean cartItem = new CartItemBean();
			ProductBean product = new ProductBean();
			product.setId(Integer.parseInt(cartItems[i].split("-")[0]));
			product.setProductByID();
			cartItem.setProduct(product);
			cartItem.setNumber(Integer.parseInt(cartItems[i].split("-")[1]));
			cart.add(cartItem);
		}
		
		return cart;
	}
	
}
